package command.fileComm;

import command.Command;
import empty.files.MyFile;
import empty.log.Log;
import model.log.LogModel;
import server.ServerThread;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class FileDownloadCommand extends Command {
    @Override
    public void excute() {

    }

    @Override
    public void excute(ServerThread st) {
        try {
            MyFile myFile = (MyFile) this.o;
            // 获取文件
            Path path1 = Paths.get(path);
            this.bytes = Files.readAllBytes(path1);
            // log
            Log log = new Log("下载文件："+path1.toAbsolutePath(),st.getUser().getId(),myFile.getCreate_time());
            new LogModel().insertLog(log);

            this.r = true;
        }
        catch (Exception ex){
            ex.printStackTrace();
            this.e = ex;
            this.r = false;
        }
    }
}
